package sedev.shopping.business;

import sedev.shopping.data.ThongTinShopDAO;
import sedev.shopping.entities.ListThongTinShop;
import sedev.shopping.entities.ThongTinShop;
import sedev.shopping.util.Paging;
import sedev.shopping.util.SedevUtil;

public class ThongTinShopService {

	public static boolean addData(ThongTinShop data) {
		ThongTinShopDAO dao = new ThongTinShopDAO();
		return dao.addData(data);
	}

	public static boolean updateData(ThongTinShop data) {
		ThongTinShopDAO dao = new ThongTinShopDAO();
		return dao.updateData(data);
	}

	public static boolean removeData(long id) {
		ThongTinShopDAO dao = new ThongTinShopDAO();
		return dao.removeData(id);
	}

	public static ThongTinShop getData(long id) {
		ThongTinShopDAO dao = new ThongTinShopDAO();
		return dao.getData(id);
	}
	
	public static ThongTinShop getDataByUser(long id) {
		StringBuilder condition = new StringBuilder();
		condition.append(ThongTinShop.Properties.user_id.name()).append("=").append(id);
		
		ThongTinShopDAO dao = new ThongTinShopDAO();
		return dao.getData(condition.toString());
	}

	public static ListThongTinShop getListData(SedevUtil.ModeDisplay mode_display, Paging paging) {
		StringBuilder field = new StringBuilder();
		field.append(ThongTinShop.Properties.id.name());
		field.append(",").append(ThongTinShop.Properties.user_id.name());
		field.append(",").append(ThongTinShop.Properties.ten_shop.name());
		field.append(",").append(ThongTinShop.Properties.hien_thi.name());

		StringBuilder condition = new StringBuilder();
		condition.append("1 AND 1");
		switch (mode_display) {
			case Display:
				condition.append(" AND ").append(ThongTinShop.Properties.hien_thi.name()).append("= 1");
				break;
			case Hide:
				condition.append(" AND ").append(ThongTinShop.Properties.hien_thi.name()).append("= 0");
				break;
			default:
				break;
		}

		ThongTinShopDAO dao = new ThongTinShopDAO();
		return dao.getListData(field.toString(), condition.toString(), "", paging);
	}
}
